package pruebaBuilder;

public class HTMLDocumentBuilder implements IDocumentBuilder {

	private HTMLDocument document;
	
	public HTMLDocumentBuilder() {
        document = new HTMLDocument();
    }
	
	@Override
	public IDocumentBuilder buildBody(String text) {
		this.document.setBody(text);
		return this;
	}

	@Override
	public IDocumentBuilder buildTitle(String title) {
		this.document.setTitle(title);
		return this;
	}

	@Override
	public IDocument getDocument() {
		return this.document;
	}	
	
	private static class HTMLDocument implements IDocument {

        private String title;
        private String body;
        
        @Override
        public String toText() {
            StringBuilder builder = new StringBuilder();
            builder.append("<html>\n");
            builder.append("\t<head>\n");
            builder.append("\t\t<title>\n");
            builder.append("\t\t\t");
            builder.append(title);
            builder.append("\n");
            builder.append("\t\t</title>\n");
            builder.append("\t</head>\n");
            builder.append("\t<body>\n");
            builder.append("\t\t");
            builder.append(body);
            builder.append("\n");
            builder.append("\t</body>\n");
            builder.append("</html>\n");
            return builder.toString();
        }

        /**
         * @param title the title to set
         */
        public void setTitle(String title) {
            this.title = title;
        }

        /**
         * @param body the body to set
         */
        public void setBody(String body) {
            this.body = body;
        }
    }
}
